// pages/shop/print.js
var app = getApp();
Page({
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady: function(){
    var that = this;
    //TODO: 可以直接本地读取了
    app.func.req('shops/show', {
      id: wx.getStorageSync('shop').id
    }, 'GET', function (res) {
      var shop = res.result;
      console.log(shop)
      that.setData({
        print_code: shop.print_code,
        print_secret: shop.print_secret,
        print_num: shop.print_num
      });
    }, {
        'token': wx.getStorageSync('token')
      });
  },
  save:function(e){
    var that = this;
    app.func.req('shops/update', {
      print_code: e.detail.value.print_code,
      print_secret: e.detail.value.print_secret,
      print_num: e.detail.value.print_num
    }, 'POST', function (res) {
      console.log(res)
      if (res.code == 'success') {
        wx.showToast({
          title: '保存成功',
          duration: 3000,
          success: function () {
            wx.switchTab({
              url: './shop'
            })
          }
        });
      } else {
        wx.showToast({
          title: '保存失败',
          image: '/images/fail.png',
          duration: 3000
        })
      }
    }, {
        'token': wx.getStorageSync('token')
      });
  }
})
